//require 存在的意义是帮助我们引入js模块
require(['./config'], () => {
    //有返回值得参数放前边
    require(['swiper','template','header', 'footer'], (Swiper,template) => {
        class Index {
            constructor() {
                this.banner()
                this.getCake ()
            }
            banner(){
                new Swiper('.lunbo',{
                    //循环模式选项
                    loop:true,
                    slidesPerView: 1,
                    spaceBetween: 30,
                    //如果需要分页器
                    pagination: {
                        el: '.swiper-pagination',
                        clickable: true,
                      },
                    //如果需要前进后退按钮
                    navigation: {
                        nextEl: '.swiper-button-next',
                        prevEl: '.swiper-button-prev',
                      },
                })
            }
            getCake () {
                $.get('http://rap2api.taobao.org/app/mock/241019/cake', resp => {
                  if (resp.code === 200) {
                    const { list } = resp.body
                    // const list = resp.body.list
                    // 如果模板里的字段名和这里传递的数据变量名写法一样就可以解构赋值只写一次
                    const html = template('cakeTemplate', { list })
                    $('#cakeList').html(html)
                  }
                })
              }
        }
        new Index()
    })
})